package com.xs.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

/**
 * @author xs
 * date 2018/1/11 15:34
 */
@RestController
public class DcController {
    @Autowired
    DiscoveryClient discoveryClient;

    @GetMapping("/dc")
    public String dc() throws InterruptedException {
//        if(needSleep())
//        Thread.sleep(3000L);
        String services = "Services: " + discoveryClient.getServices();
        System.out.println(services);
        return services;
    }

    private boolean needSleep() {
        int max = 5;
        int min = 0;
        Random random = new Random();
        int s = random.nextInt(max) % (max - min + 1) + min;
        return s>3;
    }
}
